package com.lance.shiro.service;

import com.lance.shiro.entity.ISolicitor;
import com.lance.shiro.mapper.SolicitorMapper;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
@Transactional
public class SolicitorService extends GenericCrudService<ISolicitor> {


    private SolicitorMapper mapper;

    @Autowired
    public SolicitorService(SolicitorMapper mapper) {
        super(mapper);
        this.mapper = mapper;
    }


    @Override
    public ISolicitor insert(ISolicitor o) {

        ISolicitor tmp = mapper.fetchByBean(o);

        if (tmp == null) {
            return super.insert(o);
        }

        return tmp;
    }

    public List<ISolicitor> findEamilByIds(String ids) {
        List<ISolicitor> list = new ArrayList<>();
        if (ids != null) {
            String idss = "'" + StringUtils.join(ids.split(","), "','") + "'";
            list = mapper.findAllByIds(idss);
        }
        return list;
    }
}